home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / CAT.C < prev    next >
Text File  |  1987-06-18  |  768b  |  35 lines

  1.  
  2.   /* (This program is from p. 154 of the Kernighan and Ritchie text */
  3. #include <stdio.h>
  4.  
  5. main(argc, argv)        /* cat: concatenate files */
  6. int argc;
  7. char *argv[];
  8. {
  9.     FILE *fp, *fopen();
  10.  
  11.     if (argc == 1) /* no args; copy standard input */
  12.          filecopy(stdin);
  13.     else
  14.          while (--argc > 0)
  15.             if ((fp = fopen(*++argv, "r")) == NULL) {
  16.                 fprintf(stderr,
  17.                         "cat: can't open %s\n", *argv);
  18.                 exit(1);
  19.             } else {
  20.                 filecopy(fp);
  21.                 fclose(fp);
  22.             }
  23.     exit(0);
  24. }
  25.  
  26. filecopy(fp)    /* copy file fp to standard output */
  27. FILE *fp;
  28. {
  29.     int c;
  30.  
  31.     while ((c = getc(fp)) != EOF)
  32.         putc(c, stdout);
  33. }
  34.  
  35.